//package com.wwd.movie.common.util;
//
//import com.google.gson.Gson;
//import com.qiniu.common.QiniuException;
//import com.qiniu.http.Response;
//import com.qiniu.storage.Configuration;
//import com.qiniu.storage.Region;
//import com.qiniu.storage.UploadManager;
//import com.qiniu.storage.model.DefaultPutRet;
//import com.qiniu.util.Auth;
//import com.wwd.movie.common.config.QiniuConfig;
//import jakarta.annotation.PostConstruct;
//import org.springframework.stereotype.Component;
//
//import java.io.ByteArrayInputStream;
//import java.io.InputStream;
//import java.nio.charset.StandardCharsets;
//
///**
// * 七牛云上传工具类（Spring Boot风格）
// */
//@Component
//public class QiniuUploadUtil {
//
//    private final QiniuConfig qiniuConfig;
//
//    private UploadManager uploadManager;
//    private Auth auth;
//
//    public QiniuUploadUtil(QiniuConfig qiniuConfig) {
//        this.qiniuConfig = qiniuConfig;
//    }
//
//    @PostConstruct
//    private void init() {
//        // 初始化配置，指定 Region
//        Configuration cfg = new Configuration(Region.region0());
//        cfg.resumableUploadAPIVersion = Configuration.ResumableUploadAPIVersion.V2;
//
//        this.uploadManager = new UploadManager(cfg);
//        this.auth = Auth.create(qiniuConfig.getAccessKey(), qiniuConfig.getSecretKey());
//    }
//
//    /**
//     * 上传字节数组
//     */
//    public DefaultPutRet upload(byte[] data, String key) throws QiniuException {
//        ByteArrayInputStream byteInputStream = new ByteArrayInputStream(data);
//        return upload(byteInputStream, key);
//    }
//
//    /**
//     * 上传字符串
//     */
//    public DefaultPutRet upload(String content, String key) throws QiniuException {
//        byte[] data = content.getBytes(StandardCharsets.UTF_8);
//        return upload(data, key);
//    }
//
//    /**
//     * 上传 InputStream
//     */
//    public DefaultPutRet upload(InputStream inputStream, String key) throws QiniuException {
//        String upToken = auth.uploadToken(qiniuConfig.getBucket());
//        Response response = uploadManager.put(inputStream, key, upToken, null, null);
//        return new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
//    }
//
//    /**
//     * 获取文件外链
//     */
//    public String getFileUrl(String key) {
//        return "http://your-cdn-domain/" + key; // 这里可以换成你的 CDN 域名
//    }
//}
